package net.jacqeush.mini.server.config;



import net.jacqeush.mini.server.RpcServer;

import java.util.List;

/**
 * @author Jacquesh
 * @version 1.0
 * @date 2020/10/17 4:47
 */
public class RpcServerConfig {
    private final String host = "127.0.0.1";

    protected int port;

    private List<ProviderConfig> providerConfigs ;

    private RpcServer rpcServer = null;

    public RpcServerConfig(List<ProviderConfig> providerConfigs) {
        this.providerConfigs = providerConfigs;
    }

//    /**
//     * RpcServerConfig
//     * @param providerConfigs 服务提供方的元数据信息列表
//     * @param rpcRegistryProviderService 注册服务
//     */
//    public RpcServerConfig(List<ProviderConfig> providerConfigs,
//                           RpcRegistryProviderService rpcRegistryProviderService) {
//        this.providerConfigs = providerConfigs;
//        this.rpcRegistryProviderService = rpcRegistryProviderService;
//    }

    public void exporter() {
        if(rpcServer == null) {
            try {
                rpcServer = new RpcServer(host + ":" + port);
            } catch (Exception e) {

            }
        }
        for(ProviderConfig providerConfig: providerConfigs) {
            try {
                rpcServer.registerProcessor(providerConfig);
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }

    public RpcServer getRpcServer() {
        return rpcServer;
    }

    public void setRpcServer(RpcServer rpcServer) {
        this.rpcServer = rpcServer;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }
}
